package com.usian.controller;

import com.usian.pojo.User;
import com.usian.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/login")
public class LoginController {

    @Autowired
    LoginService loginService;

    @RequestMapping("/login")
    public String login(User user, HttpSession session) {
        User user1 = loginService.login(user);
        if (user1.getUstart() == 0) {
            session.setAttribute("user", user1);
            //运营权限数据
            return "redirect:/commodity/findAll";
        }

        if (user1.getUstart() == 1) {
            //管理权限数据
            return "redirect:/commodity/findAllAnd";
        } else {
            return "login";
        }

    }

    @RequestMapping("/toLogin")
    public String toLogin() {
        return "login.html";
    }
}
